<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">{{message}}</div>
  <!-- <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script> -->
  <input type="text">
  <p></p>
  <script>
    const ipt = document.querySelector('input')
    const p = document.querySelector('p')
    // var app = new Vue({
    //     el: '#app',
    //     data: {
    //       message: 'Hello Vue!'
    //     }
    //   })
    // console.log(app);
    const data = { name: 'zs' }
    const _data = {}
    const watch = {
      name(val){
        console.log(val)
      }
    }

    Object.defineProperty(_data, 'name', {
      get: function reactiveGetter (){
        return data.name
      },
      set:function reactiveSetter(val){ // set触发的条件是当前这个name属性被改了才会触发
        console.log(val);
        // 将最新的值 反向赋值给 data
        data.name = val
        ipt.value = _data.name
        p.innerHTML = val
        watch.name && watch.name(val)
      }
    })
    console.log(_data);
    // 数据展示在视图中
    ipt.value = _data.name
    p.innerHTML = _data.name
    // 视图驱动数据
    ipt.addEventListener('input', (e)=>{
      console.log(e.target.value);
      _data.name = e.target.value
    })
  
  </script>
</body>
</html>